home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / ada / c01oop.zip / CPPWKBK / CPPV3-2.CPP < prev    next >
C/C++ Source or Header  |  1992-08-25  |  995b  |  51 lines

  1. #define HEADER "C++ Problem 3.2 by Rick Conn using Borland C++"
  2.  
  3. #include <stdio.h>
  4. #include <string.h>  // for strcpy()
  5.  
  6. const max_string_length = 100;
  7.  
  8. class string {
  9.   char data[max_string_length];
  10.   static int number_of_strings;
  11. public:
  12.   string (char *);
  13.   static int count (void);
  14.   void print (void);
  15. };
  16.  
  17. int string::number_of_strings = 0;
  18.  
  19. string::string(char *new_string) {
  20.   strcpy(data, new_string);
  21.   string::number_of_strings++;
  22. }
  23.  
  24. int string::count(void) {
  25.   return number_of_strings;
  26. }
  27.  
  28. void string::print(void) {
  29.   printf("String = \"%s\"\n", data);
  30. }
  31.  
  32. void main(void)
  33. {
  34.   printf("%s\n", HEADER);
  35.  
  36.   string s1("This is a test");
  37.   string s2("This is only a test");
  38.   string s3("This is fun");
  39.   printf("The count is %d\n", string::count());
  40.  
  41.   string s4("Another string");
  42.   string s5("Yet another string");
  43.   printf("The count is %d\n", string::count());
  44.  
  45.   s1.print();
  46.   s2.print();
  47.   s3.print();
  48.   s4.print();
  49.   s5.print();
  50. }
  51.